package com.seculab.admin.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.util.WebUtils;

import com.seculab.admin.domain.User;
import com.seculab.admin.service.DwrServiceImpl;

public class SignOnInterceptor implements HandlerInterceptor {
	private static final Logger logger = Logger.getLogger(SignOnInterceptor.class);
	@Override
	public void afterCompletion(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
			Object arg2, ModelAndView arg3) throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
			Object handler) throws Exception {
		logger.debug("interceptor prehandle executed");
		User userSession = (User)WebUtils.getSessionAttribute(request, "loginUser");
		
		if(userSession == null) {
			String url = request.getServletPath();
			String query = request.getQueryString();
			ModelAndView mav = new ModelAndView("redirect:login");
			
			if(query != null) {
				
			} else {
				
			}
			
			return false;
		} else {
			return true;
		}
		
	}

}
